//
//  Rank.swift
//  DemoUI
//  冒泡排序
//  Created by 白瑾浩 on 2022/6/16.
//

import Foundation
class Rank{
    static func test(){
        var a = [1,2,5,6,1,2]
        for i in 0..<a.count-1{  // 0..<5
            //默认有序
            var isOrdered = true
            for j in 0..<a.count-1-i{  //0..<5  0..<4 0..<3 0..<2 0..<1 0..<0
                
                if a[j] > a[j+1]{
                    let t = a[j]
                    a[j] = a[j+1]
                    a[j+1] = t
                    isOrdered = false
                }
                
            }
            //如果有序退出循环
            if(isOrdered){break}
        }
        
        print( "b===\(a)" )
    }
}
